package cn.itcast.controller;

import cn.itcast.constant.MessageConstant;
import cn.itcast.entity.Result;
import cn.itcast.pojo.Member;
import cn.itcast.service.SmsService;
import com.alibaba.dubbo.config.annotation.Reference;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.*;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionContext;
import java.util.Map;

/**
 * @Author: ZHT
 * @Dtae: 2021/11/16 13:00
 * @Version: 1.0
 */
@Slf4j
@RestController
@RequestMapping(path = "/member")
@CrossOrigin
public class LoginController {

      @Reference
      public   SmsService smsService;

    @RequestMapping("/login")
    public Result Login(HttpServletRequest request) {

        //获取验证码

        //String validateCode = param.get("validateCode");
        String validateCode = 123456+"";
        String validateCode1 = request.getServletContext().getAttribute("s").toString();
        request.getServletContext().setAttribute("validateCode1",validateCode1);
        System.out.println(request.getServletContext().getAttribute("validateCode1"));
        log.info("系统发送的验证码为{}用户输入的验证码为{}",validateCode1,validateCode);

        if(validateCode1.equals(validateCode)){
            request.getServletContext().setAttribute("validateCode1",validateCode1);
            return new Result(true, MessageConstant.LOGIN_SUCCESS );
        }
        return new Result(false, MessageConstant.VALIDATECODE_ERROR);

    }
}